.org 0xC86CC ; Damage to Funds

Damage_To_Funds.asm:

	PUSH 	{R4-R8, LR}	

	LDR 	R4, [Damage_To_Funds_1]
	LDR 	R3, [Damage_To_Funds_2]
	LDR 	R4, [R4, 0]
	LDR 	R3, [R3, 0]
	
	MOV		R8, R1
	ADD 	R1, R4, R3, LSL 2
	LDR 	R1, [R1, 0x48]
	LDR		R3, [Damage_To_Funds_3]
	ADD 	R5, R1, 0x5000
	LDR 	R1, [R5, 0x75C]
	MOV 	R4, 0x98
	SUB		R6, R0, R1
	SMULL	R0, R7, R3, R6
	SUB		R12, R8, R1
	ADD		R7, R6, R7
	SMULL	R1, R0, R3, R12
	ADD		R0, R12, R0
	MOV		R7, R7, ASR 3
	MOV		R1, R6, LSR 0x1F
	ADD 	R7, R1, R7
	MOV		R1, R7, ASR 6
	ADD		R6, R1, 1
	MUL		R4, R6, R4
	LDR 	R3, [R5, 0xA58]
	MOV		R0, R0, ASR 3
	MOV		R7, R2
	MOV		R1, R12, LSR 0x1F
	ADD		R0, R1, R0
	MOV		R0, R0, ASR 6
	ADD		R5, R0, 1
	ADD		R0, R3, R4
	ADD		R0, R0, 0x74
	
	MOV 	R1, Rank_Combat_Pay					; Rank: Combat Pay
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	BEQ		No_Combat_Pay
	
	LDRB	R1, [R8, 0]
	MOV		R0, R5
	
	BL		Damage_To_Funds_Sub1
	
	MUL	R0, R7, R0
	MOV	R0, R0, LSL 1							; 2% converted to Funds 
	MOV 	R1, 100	
	
	BL		Damage_To_Funds_Sub2
	
	MOV		R2, R6, LSL 0x10
	MOV		R1, R0
	MOV		R0, R2, LSR 0x10
	
	BL		Damage_To_Funds_Sub3

No_Combat_Pay:	
	LDR 	R1, [Damage_To_Funds_1]
	LDR 	R0, [Damage_To_Funds_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, CO_Firepower_Funds				; Skill: Firepower to Funds
	
	ADD 	R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	ADD 	R0, R0, 0x5000	
	LDR 	R0, [R0, 0xA58]
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74

	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	POPEQ 	{R4-R8, LR}	
	BXEQ	LR
	
	LDRB	R1, [R8, 0]
	MOV		R0, R5
	
	BL		Damage_To_Funds_Sub1
	
	MUL		R1, R7, R0
	MOV		R0, 50								; 50% converted to Funds 
	MUL		R0, R1, R0
	MOV 	R1, 100	
	
	BL		Damage_To_Funds_Sub2
	
	MOV		R2, R6, LSL 0x10
	MOV		R1, R0
	MOV		R0, R2, LSR 0x10
	
	BL		Damage_To_Funds_Sub3
	
	POP 	{R4-R8, LR}
	BX		LR									

;-------------------------------------------------------------------------------		

Damage_To_Funds_1:
	.dw Reg1_Skill
	
Damage_To_Funds_2:
	.dw Reg2_Skill
	
Damage_To_Funds_3:
	.dw 0x92492493
	
;-------------------------------------------------------------------------------		

.org 0xE0314
Damage_To_Funds_Sub1:

.org 0x2FA4
Damage_To_Funds_Sub2:

.org 0xC83D0
Damage_To_Funds_Sub3:


